package com.ruoyi.module.websiteMember.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.module.websiteMember.domain.WebsiteMember;
import com.ruoyi.module.websiteMember.service.IWebsiteMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 微官网Controller
 * 
 * @author ruoyi
 * @date 2024-01-26
 */
@RestController
@RequestMapping("/api/website/member")
public class WebsiteMemberController extends BaseController
{
    @Autowired
    private IWebsiteMemberService websiteMemberService;

    /**
     * 查询微官网列表
     */
    // @PreAuthorize("@ss.hasPermi('system:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(WebsiteMember websiteMember)
    {
        startPage();
        List<WebsiteMember> list = websiteMemberService.selectWebsiteMemberList(websiteMember);
        return getDataTable(list);
    }

    /**
     * 导出微官网列表
     */
    // @PreAuthorize("@ss.hasPermi('system:member:export')")
    @Log(title = "微官网", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WebsiteMember websiteMember)
    {
        List<WebsiteMember> list = websiteMemberService.selectWebsiteMemberList(websiteMember);
        ExcelUtil<WebsiteMember> util = new ExcelUtil<WebsiteMember>(WebsiteMember.class);
        util.exportExcel(response, list, "微官网数据");
    }

    /**
     * 获取微官网详细信息
     */
    // @PreAuthorize("@ss.hasPermi('system:member:query')")
    @GetMapping(value = "/{websiteId}")
    public AjaxResult getInfo(@PathVariable("websiteId") Long websiteId)
    {
        return success(websiteMemberService.selectWebsiteMemberByWebsiteId(websiteId));
    }

    /**
     * 新增微官网
     */
    // @PreAuthorize("@ss.hasPermi('system:member:add')")
    @Log(title = "微官网", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WebsiteMember websiteMember)
    {
        return toAjax(websiteMemberService.insertWebsiteMember(websiteMember));
    }

    /**
     * 修改微官网
     */
    // @PreAuthorize("@ss.hasPermi('system:member:edit')")
    @Log(title = "微官网", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WebsiteMember websiteMember)
    {
        return toAjax(websiteMemberService.updateWebsiteMember(websiteMember));
    }

    /**
     * 删除微官网
     */
    // @PreAuthorize("@ss.hasPermi('system:member:remove')")
    @Log(title = "微官网", businessType = BusinessType.DELETE)
	@DeleteMapping("/{websiteIds}")
    public AjaxResult remove(@PathVariable Long[] websiteIds)
    {
        return toAjax(websiteMemberService.deleteWebsiteMemberByWebsiteIds(websiteIds));
    }
}
